﻿using System.Globalization;
using System.Windows.Controls;

namespace PMIS.Common.DataValidation
{
    public class NumericValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string input = value as string;
            if (string.IsNullOrEmpty(input))
            {
                return new ValidationResult(false, "请输入数字");
            }

            if (double.TryParse(input, out _))
            {
                return ValidationResult.ValidResult;
            }
            else
            {
                return new ValidationResult(false, $"未能转换值“{input}”。请输入有效的数字。");
            }
        }
    }
}
